package com.zd.bms.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zd.bms.bean.vo.req.SystemLogListReqVo;
import com.zd.bms.service.ISysLogService;
import com.zd.common.bean.model.SysLog;
import com.zd.common.common.utils.DateTimeUtil;
import com.zd.common.common.utils.StringUtils;
import com.zd.common.dao.SysLogDao;
import com.zd.common.dao.common.BaseDao;
import com.zd.common.dao.common.FindRequestEntity;
import com.zd.common.dao.common.OrderEnum;
import com.zd.common.dao.common.Page;
import com.zd.common.dao.common.WhereEnum;
import com.zd.common.service.impl.BaseServiceImpl;

@Service
public class SysLogServiceImpl extends BaseServiceImpl<SysLog> implements ISysLogService {
	@Autowired
	private SysLogDao sysLogDao;

	@Override
	public BaseDao<SysLog> getBaseDao() {
		return sysLogDao;
	}

	@Override
	public Page<SysLog> pageSysLog(SystemLogListReqVo req) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		if (req.getScenicSpotId() != null && req.getScenicSpotId() != 0) {
			findReq.addWhere("scenic_spot_id", WhereEnum.EQ, req.getScenicSpotId());
		}

		if (!StringUtils.isBank(req.getStartTime())) {
			findReq.addWhere("create_time", WhereEnum.GE, DateTimeUtil.string2Date(req.getStartTime()));
		}

		if (!StringUtils.isBank(req.getEndTime())) {
			findReq.addWhere("create_time", WhereEnum.LE, DateTimeUtil.string2Date(req.getEndTime()));
		}

		findReq.addOrder("create_time", OrderEnum.DESC);
		findReq.setPage(req.getPageNo(), req.getPageSize());
		Page<SysLog> resultPage = page(findReq);
		return resultPage;
	}
}
